import "../static/libs/flexible"
import "../scss/common.scss"
import "../scss/index.scss"
import http from "../utils/http"

function main() {
    renderType() //渲染考试类型
    //点击导航跳转
    jump()
}
main()

//渲染考试类型
async function renderType() {
    const { data } = await http({ url: "/types/" })
    const result = data.map(element => {
        return `
        <div id="${element._id}" class="con1">
            <img src="${element.img}" alt="">
            <p>${element.type}</p>
        </div>
        `
    });
    $(".content .content1").html(result.join(""))
    toTest() //跳转到考试页面
}

//跳转到考试页面
function toTest() {
    $(".content .con1").on("click", function () {
        const id = $(this).attr("id")
        window.location.assign("test.html?" + id)
    })
}

//点击跳转
function jump() {
    $(".header .head_right").on("click",function(){
        if ($(".header .wrapper").css("display") == "none") {
            $(".header .wrapper").css("display","block")
            $(".header .wrapper .menu li").on("click", function () {
                const text = $(this).text()
                console.log(text);
                if (text == "首页") {
                    window.location.assign("index.html")
                } else if (text == "错题本") {
                    window.location.assign("errors.html")
                } else if (text == "收藏夹") {
                    window.location.assign("collection.html")
                } else if (text == "登录") {
                    window.location.assign("login.html")
                } else if (text == "个人中心") {
                    window.location.assign("personalCenter.html")
                }
            })
        } else {
            $(".header .wrapper").css("display","none")
        }
    })
}